﻿#!/usr/bin/env python3

import dbm

class Car:
    def __init__(self, logo, category):
        self.logo = logo
        self.category = category
    def show(self):
        print("logo:{0}, category:{1}".format(self.logo, self.category))

def main():
    '''dbm -  Interfaces to Unix “databases” 
以byte形式保存'''
    print(main.__doc__)
    print("="*30)

    db = dbm.open("car.dbm", 'c')
    db['logo']='Greate Wall'
    db['category']="SUV"
    db.close()

    db = dbm.open("car.dbm",'c')
    for key,value in db.items():
        print("{0}:{1}".format(key.decode("utf-8"),value.decode("utf-8")))
    db.close()

if __name__=='__main__':
    main()
